package com.monolithiot.sso.common.entity;

import com.monolithiot.sso.common.context.Constants;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 2018/12/10 Create by 郭文梁
 * User
 * 用户实体类
 *
 * @author 郭文梁
 * @date 2018/12/10
 */
@Data
@Table(name = "tb_user")
public class User {
    /**
     * 性别：未知
     */
    public static final int GENDER_UNKNOWN = 0;
    /**
     * 性别：男
     */
    public static final int MALE = 1;
    /**
     * 性别：女
     */
    public static final int FEMALE = 2;

    /**
     * 默认重要等级
     */
    public static final int DEFAULT_LEVELS_OF_IMPORTANCE = 0;
    /**
     * ID
     * id                   int(10)      not null auto_increment
     * primary key (id)
     */
    @Id
    @GeneratedValue(generator = Constants.SQL.GENERATOR_JDBC)
    @Column(name = "id", length = 10, nullable = false)
    private Integer id;
    /**
     * 用户名
     * name                 varchar(100) not null
     */
    @Column(name = "name", length = 100, nullable = false)
    private String name;
    /**
     * 密码
     * password             varchar(100) not null
     */
    @Column(name = "password", length = 100, nullable = false)
    private String password;
    /**
     * 手机号
     * mobile_number        varchar(20)  null
     */
    @Column(name = "mobile_number", length = 20)
    private String mobileNumber;
    /**
     * 座机号
     * phone_number         varchar(20)  null
     */
    @Column(name = "phone_number", length = 20)
    private String phoneNumber;
    /**
     * 邮箱
     * email                varchar(50)  null
     */
    @Column(name = "email", length = 50)
    private String email;
    /**
     * 头像保存路径
     * head_portrait        varchar(255) null
     */
    @Column(name = "head_portrait")
    private String headPortrait;
    /**
     * 用户性别
     * gender               INT(1)       NOT NULL  DEFAULT 0
     * COMMENT '用户性别',
     */
    @Column(name = "gender", length = 1, nullable = false)
    private Integer gender;
    /**
     * 地址 省
     * province             varchar(100) null
     */
    @Column(name = "province", length = 100)
    private String province;
    /**
     * 地址 市
     * city                 varchar(100) null
     */
    @Column(name = "city", length = 100)
    private String city;
    /**
     * 地址 区
     * district             varchar(100) null
     */
    @Column(name = "district", length = 100)
    private String district;
    /**
     * 详细地址
     * address              varchar(255) null
     */
    @Column(name = "address")
    private String address;
    /**
     * 从事行业
     * industry             varchar(255) null
     */
    @Column(name = "industry")
    private String industry;
    /**
     * 星标等级
     * levels_of_importance int(2)       not null default 0
     */
    @Column(name = "levels_of_importance", length = 2)
    private Integer levelsOfImportance;

    /**
     * 克隆新对象，并将原对象中的headPortrait替换为绝对URL
     *
     * @param prefix 前缀
     * @return User Entity
     */
    public User cloneAsPrettyPath(String prefix) {
        User user = new User();
        BeanUtils.copyProperties(this, user);
        if (user.headPortrait != null) {
            user.headPortrait = prefix +
                    '/' +
                    user.headPortrait;
        }
        return user;
    }
}
